package com.chenwc.enums;

/**
 * MessageDigest 支持的算法枚举
 *
 * @author 陈为成
 *
 */
public enum AlgorithmEnum {

    MD2("MD2"),
    MD5("MD5"),
    SHA_1("SHA-1"),
    SHA_224("SHA-224"),
    SHA_256("SHA-256"),
    SHA_384("SHA-384"),
    SHA_512("SHA-512");
    //JDK 9 及之后版本支持
    //SHA_512_224("SHA-512/224"),
    //SHA_512_256("SHA-512/256"),
    //SHA3_224("SHA3-224"),
    //SHA3_256("SHA3-256"),
    //SHA3_384("SHA3-384"),
    //SHA3_512("SHA3-512");

    private String algorithm;

    AlgorithmEnum(String algorithm) {
        this.algorithm = algorithm;
    }

    public String getAlgorithm() {
        return algorithm;
    }

    public void setAlgorithm(String algorithm) {
        this.algorithm = algorithm;
    }

    /**
     * 根据算法名称获取 AlgorithmEnum
     * @param algo 算法名称
     * @return AlgorithmEnum
     */
    public AlgorithmEnum getAlgorithmEnum(String algo) {
        for (AlgorithmEnum algorithmEnum : AlgorithmEnum.values()) {
            if (algo.equals(algorithmEnum.getAlgorithm())) {
                return algorithmEnum;
            }
        }
        return null;
    }
}
